package cn.nebula.music.controller;

import java.util.HashMap;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import cn.nebula.music.domain.Singer;
import cn.nebula.music.service.AlbumService;
import cn.nebula.music.service.ClassificationService;
import cn.nebula.music.service.CombinationService;
import cn.nebula.music.service.PictureService;
import cn.nebula.music.service.SingerService;
import cn.nebula.music.service.SongService;
import cn.nebula.music.service.UserService;

@Controller
public class SingerController {

	@Autowired
	private SingerService singerService;

	@Autowired
	private AlbumService albumService;

	@Autowired
	private PictureService pictureService;

	@Autowired
	private SongService songService;

	@Autowired
	private ClassificationService classificationService;

	@Autowired
	private UserService userService;

	@Autowired
	private CombinationService combinationService;

	@RequestMapping("/editSinger")
	@ResponseBody
	public Map<String, Object> editSinger(@RequestParam Integer id) throws Exception {
		Map<String, Object> values = new HashMap<String, Object>();
		values.put("singer", singerService.findSingerById(id));
		values.put("albums", albumService.findAllAlbumsOfBT());
		values.put("pictures", pictureService.findAllPicturesOfBT());
		values.put("songs", songService.findAllSongsOfBT());
		values.put("classifications", classificationService.findAllClassificationsOfBT());
		values.put("users", userService.findAllUsersOfBT());
		values.put("combinations", combinationService.findAllCombinationsOfBT());
		return values;
	}

	@RequestMapping("/listAllSingers")
	@ResponseBody
	public Map<String, Object> listAllSingers() throws Exception {
		Map<String, Object> values = new HashMap<String, Object>();
		values.put("singers", singerService.findAllSingersOfBT());
		return values;
	}

	@RequestMapping("/newSinger")
	@ResponseBody
	public Map<String, Object> newSinger() throws Exception {
		Map<String, Object> values = new HashMap<>();
		values.put("albums", albumService.findAllAlbumsOfBT());
		values.put("pictures", pictureService.findAllPicturesOfBT());
		values.put("songs", songService.findAllSongsOfBT());
		values.put("classifications", classificationService.findAllClassificationsOfBT());
		values.put("users", userService.findAllUsersOfBT());
		values.put("combinations", combinationService.findAllCombinationsOfBT());
		return values;
	}

	@RequestMapping("/updateSinger")
	@ResponseBody
	public boolean updateSinger(@RequestBody Singer singer) throws Exception {
		System.out.println(singer);
		singerService.updateSinger(singer);
		return true;
	}

	@RequestMapping("/addSinger")
	@ResponseBody
	public boolean addSinger(@RequestBody Singer singer) throws Exception {
		singerService.addSinger(singer);
		return true;
	}

	@RequestMapping("/deleteSinger")
	@ResponseBody
	public boolean deleteSinger(@RequestParam Integer id) throws Exception {
		singerService.deleteSingerById(id);
		return true;
	}

}
